import axios from "axios";
import {message} from "antd";

//创建axios实例
const Axios = axios.create({
  baseURL: '/fras'
})


//设置请求拦截器， 为请求添加Authorization的token
Axios.interceptors.request.use(
  config => {
    if (sessionStorage.getItem('my_token')) {
      config.headers.Authorization = sessionStorage.getItem('my_token')
    }
    return config
  },
  error => {
    return Promise.reject(error);
  }
)
//响应拦截器
Axios.interceptors.response.use(
  response => {
    if (response.data.code === 2001 || response.data.code === 2009) {
      window.location.hash = "/"
      message.error('登录状态异常！')
    }
    return response
  },
  error => {
    return Promise.reject(error);
  }
)

export default Axios